<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .mycanvas{
      border: 2px solid black;
    }
  </style>
</head>
<body>
  <canvas class="mycanvas" width="1000px" height="800px"></canvas>
</body>
<script>

  var mycanvas = document.querySelector('.mycanvas');
  var ctx = mycanvas.getContext('2d');
  ctx.translate(mycanvas.width/2,mycanvas.height/2);

  function drawShape(n){
    ctx.beginPath();
    ctx.moveTo(Math.sin(0)*100,Math.cos(0)-100);

    var radian = 2*Math.PI/n;

    for(var i = 0;i<n;i++){
      ctx.lineTo(Math.sin(radian*i)*100,Math.cos(radian*i)*-100);
    }

    ctx.closePath();
    ctx.lineWidth = 4;
    ctx.stroke();
  }

  drawShape(4);
</script>
</html>